Imports System
Imports System.ComponentModel


<System.CodeDom.Compiler.GeneratedCodeAttribute("Presentation Model Tool", "3.0.0.0")>  _
Partial Public Class Mock(Of T)
    Implements System.ComponentModel.ISupportInitialize, System.ComponentModel.ISupportInitializeNotification, System.ComponentModel.IChangeTracking, System.ComponentModel.INotifyPropertyChanged
    
    Const InitializationNotBegun As String = "Initialization has not been started."
    
    Const NotInitialized As String = "The object has not been initialized properly. Call Initialize prior to use."
    
    Private _beginCalled As Boolean
    
    Private _isInitialized As Boolean
    
    Private _isChanged As Boolean
    
    Private ReadOnly Property RequiresInitialize() As Boolean
        Get
            Return ((CType(Me,ISupportInitializeNotification).IsInitialized = false)  _
                        OrElse CType(Me,IChangeTracking).IsChanged)
        End Get
    End Property
    
    Private ReadOnly Property IsInitialized() As Boolean Implements ISupportInitializeNotification.IsInitialized
        Get
            Return (Me._isInitialized AndAlso Me.AreNestedInitialized)
        End Get
    End Property
    
    ''' <summary>Gets whether the object properties that support <see cref='ISupportInitializeNotification'/> are initialized.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable ReadOnly Property AreNestedInitialized() As Boolean
        Get
            Return true
        End Get
    End Property
    
    Private ReadOnly Property IsChanged() As Boolean Implements IChangeTracking.IsChanged
        Get
            Return (Me._isChanged OrElse Me.HasNestedChanges)
        End Get
    End Property
    
    '''<summary>Gets whether the object properties that support <see cref='IChangeTracking'/> report changes.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable ReadOnly Property HasNestedChanges() As Boolean
        Get
            Return false
        End Get
    End Property
    
    '''<summary>Signals that the object has been initialized.</summary>
    Public Event Initialized As EventHandler Implements ISupportInitializeNotification.Initialized
    
    '''<summary>Signals that a property has changed.</summary>
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    '''<summary>Signals that the property <see cref='MyValue'/> has changed.</summary>
    Public Event MyValueChanged As EventHandler
    
    '''<summary>Validates object properties and initializes it for use.</summary>
    Public Sub Initialize()
        If Me.RequiresInitialize Then
            Me.DoValidate
            Me._isChanged = false
            Me.InitializeNested
            Me.DoInitialize
            Me._isInitialized = true
            If (Not (Me.InitializedEvent) Is Nothing) Then
                RaiseEvent Initialized(Me, EventArgs.Empty)
            End If
        End If
    End Sub
    
    '''<summary>Initializes the nested properties that support <see cref='ISupportInitialize'/>.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable Sub InitializeNested()
    End Sub
    
    Private Sub BeginInit() Implements ISupportInitialize.BeginInit
        Me._beginCalled = true
    End Sub
    
    Private Sub EndInit() Implements ISupportInitialize.EndInit
        If (Me._beginCalled = false) Then
            Throw New InvalidOperationException(Mock(Of T).InitializationNotBegun)
        End If
        Me.Initialize
    End Sub
    
    '''<summary>Determines whether the value is null or its 
    '''				<see cref='ISupportInitializeNotification.IsInitialized'/> is <see langword='true' />.
    '''				</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Function IsValueInitialized(ByVal child As ISupportInitializeNotification) As Boolean
        Return ((child Is Nothing)  _
                    OrElse child.IsInitialized)
    End Function
    
    Private Sub AcceptChanges() Implements IChangeTracking.AcceptChanges
        Me.Initialize
    End Sub
    
    '''<summary>Determines whether the value is not null and has changed.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Function IsValueChanged(ByVal value As IChangeTracking) As Boolean
        Return ((Not (value) Is Nothing)  _
                    AndAlso value.IsChanged)
    End Function
    
    '''<summary>Raises the <see cref='PropertyChanged'/> event.</summary>
    '''				  <param name='property'>Name of the property that changed.</param>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Sub RaisePropertyChanged(ByVal [property] As String)
        If (Not (Me.PropertyChangedEvent) Is Nothing) Then
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs([property]))
        End If
        Me._isChanged = true
    End Sub
    
    '''<summary>
    '''Checks that the object has been properly initialized through 
    '''calls to <see cref='ISupportInitialize.BeginInit'/> and 
    '''<see cref='ISupportInitialize.EndInit'/> or the <see cref='Initialize'/> method.
    '''</summary>
    '''<exception cref='InvalidOperationException'>The object was not initialized.</exception>
    Protected Sub EnsureInitialized()
        If Me.RequiresInitialize Then
            Throw New InvalidOperationException(Mock(Of T).NotInitialized)
        End If
    End Sub
    
    '''<summary>Raises the <see cref='MyValueChanged'/> event.</summary>
    Private Sub RaiseMyValueChanged()
        If (Not (Me.MyValueChangedEvent) Is Nothing) Then
            RaiseEvent MyValueChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("MyValue")
    End Sub
End Class


<System.CodeDom.Compiler.GeneratedCodeAttribute("Presentation Model Tool", "3.0.0.0")>  _
Partial Public Class MockBase
    Implements System.ComponentModel.ISupportInitialize, System.ComponentModel.ISupportInitializeNotification, System.ComponentModel.IChangeTracking, System.ComponentModel.INotifyPropertyChanged
    
    Const InitializationNotBegun As String = "Initialization has not been started."
    
    Const NotInitialized As String = "The object has not been initialized properly. Call Initialize prior to use."
    
    Private _beginCalled As Boolean
    
    Private _isInitialized As Boolean
    
    Private _isChanged As Boolean
    
    Private ReadOnly Property RequiresInitialize() As Boolean
        Get
            Return ((CType(Me,ISupportInitializeNotification).IsInitialized = false)  _
                        OrElse CType(Me,IChangeTracking).IsChanged)
        End Get
    End Property
    
    Private ReadOnly Property IsInitialized() As Boolean Implements ISupportInitializeNotification.IsInitialized
        Get
            Return (Me._isInitialized AndAlso Me.AreNestedInitialized)
        End Get
    End Property
    
    ''' <summary>Gets whether the object properties that support <see cref='ISupportInitializeNotification'/> are initialized.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable ReadOnly Property AreNestedInitialized() As Boolean
        Get
            Return (true AndAlso Me.IsValueInitialized(TryCast(BaseObject, ISupportInitializeNotification)))
        End Get
    End Property
    
    Private ReadOnly Property IsChanged() As Boolean Implements IChangeTracking.IsChanged
        Get
            Return (Me._isChanged OrElse Me.HasNestedChanges)
        End Get
    End Property
    
    '''<summary>Gets whether the object properties that support <see cref='IChangeTracking'/> report changes.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable ReadOnly Property HasNestedChanges() As Boolean
        Get
            Return (false OrElse Me.IsValueChanged(TryCast(BaseObject, IChangeTracking)))
        End Get
    End Property
    
    '''<summary>Signals that the object has been initialized.</summary>
    Public Event Initialized As EventHandler Implements ISupportInitializeNotification.Initialized
    
    '''<summary>Signals that a property has changed.</summary>
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    '''<summary>Signals that the property <see cref='BaseIntValue'/> has changed.</summary>
    Public Event BaseIntValueChanged As EventHandler
    
    '''<summary>Signals that the property <see cref='BaseObject'/> has changed.</summary>
    Public Event BaseObjectChanged As EventHandler
    
    '''<summary>Validates object properties and initializes it for use.</summary>
    Public Sub Initialize()
        If Me.RequiresInitialize Then
            Me.DoValidate
            Me._isChanged = false
            Me.InitializeNested
            Me.DoInitialize
            Me._isInitialized = true
            If (Not (Me.InitializedEvent) Is Nothing) Then
                RaiseEvent Initialized(Me, EventArgs.Empty)
            End If
        End If
    End Sub
    
    '''<summary>Initializes the nested properties that support <see cref='ISupportInitialize'/>.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable Sub InitializeNested()
        Dim initializable As ISupportInitialize
        initializable = TryCast(BaseObject, ISupportInitialize)
        If (Not (initializable) Is Nothing) Then
            initializable.BeginInit
            initializable.EndInit
        End If
    End Sub
    
    Private Sub BeginInit() Implements ISupportInitialize.BeginInit
        Me._beginCalled = true
    End Sub
    
    Private Sub EndInit() Implements ISupportInitialize.EndInit
        If (Me._beginCalled = false) Then
            Throw New InvalidOperationException(MockBase.InitializationNotBegun)
        End If
        Me.Initialize
    End Sub
    
    '''<summary>Determines whether the value is null or its 
    '''				<see cref='ISupportInitializeNotification.IsInitialized'/> is <see langword='true' />.
    '''				</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Function IsValueInitialized(ByVal child As ISupportInitializeNotification) As Boolean
        Return ((child Is Nothing)  _
                    OrElse child.IsInitialized)
    End Function
    
    Private Sub AcceptChanges() Implements IChangeTracking.AcceptChanges
        Me.Initialize
    End Sub
    
    '''<summary>Determines whether the value is not null and has changed.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Function IsValueChanged(ByVal value As IChangeTracking) As Boolean
        Return ((Not (value) Is Nothing)  _
                    AndAlso value.IsChanged)
    End Function
    
    '''<summary>Raises the <see cref='PropertyChanged'/> event.</summary>
    '''				  <param name='property'>Name of the property that changed.</param>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Sub RaisePropertyChanged(ByVal [property] As String)
        If (Not (Me.PropertyChangedEvent) Is Nothing) Then
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs([property]))
        End If
        Me._isChanged = true
    End Sub
    
    '''<summary>
    '''Checks that the object has been properly initialized through 
    '''calls to <see cref='ISupportInitialize.BeginInit'/> and 
    '''<see cref='ISupportInitialize.EndInit'/> or the <see cref='Initialize'/> method.
    '''</summary>
    '''<exception cref='InvalidOperationException'>The object was not initialized.</exception>
    Protected Sub EnsureInitialized()
        If Me.RequiresInitialize Then
            Throw New InvalidOperationException(MockBase.NotInitialized)
        End If
    End Sub
    
    '''<summary>Raises the <see cref='BaseIntValueChanged'/> event.</summary>
    Private Sub RaiseBaseIntValueChanged()
        If (Not (Me.BaseIntValueChangedEvent) Is Nothing) Then
            RaiseEvent BaseIntValueChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("BaseIntValue")
    End Sub
    
    '''<summary>Raises the <see cref='BaseObjectChanged'/> event.</summary>
    Private Sub RaiseBaseObjectChanged()
        If (Not (Me.BaseObjectChangedEvent) Is Nothing) Then
            RaiseEvent BaseObjectChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("BaseObject")
    End Sub
End Class


<System.CodeDom.Compiler.GeneratedCodeAttribute("Presentation Model Tool", "3.0.0.0")>  _
Partial Public Class MockDerived
    
    '''<summary>Gets whether the object properties that support <see cref='IChangeTracking'/> report changes.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overrides ReadOnly Property HasNestedChanges() As Boolean
        Get
            Return ((MyBase.HasNestedChanges OrElse Me.IsValueChanged(TryCast(DerivedObject, IChangeTracking)))  _
                        OrElse Me.IsValueChanged(CType(Me.Mock,IChangeTracking)))
        End Get
    End Property
    
    ''' <summary>Gets whether the object properties that support <see cref='ISupportInitializeNotification'/> are initialized.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overrides ReadOnly Property AreNestedInitialized() As Boolean
        Get
            Return ((MyBase.AreNestedInitialized AndAlso Me.IsValueInitialized(TryCast(DerivedObject, ISupportInitializeNotification)))  _
                        AndAlso Me.IsValueInitialized(CType(Me.Mock,ISupportInitializeNotification)))
        End Get
    End Property
    
    '''<summary>Signals that the property <see cref='DerivedIntValue'/> has changed.</summary>
    Public Event DerivedIntValueChanged As EventHandler
    
    '''<summary>Signals that the property <see cref='DerivedObject'/> has changed.</summary>
    Public Event DerivedObjectChanged As EventHandler
    
    '''<summary>Signals that the property <see cref='Mock'/> has changed.</summary>
    Public Event MockChanged As EventHandler
    
    '''<summary>Initializes the nested properties that support <see cref='ISupportInitialize'/>.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overrides Sub InitializeNested()
        MyBase.InitializeNested
        Dim initializable As ISupportInitialize
        initializable = TryCast(DerivedObject, ISupportInitialize)
        If (Not (initializable) Is Nothing) Then
            initializable.BeginInit
            initializable.EndInit
        End If
        initializable = CType(Me.Mock,ISupportInitialize)
        If (Not (initializable) Is Nothing) Then
            initializable.BeginInit
            initializable.EndInit
        End If
    End Sub
    
    '''<summary>Raises the <see cref='DerivedIntValueChanged'/> event.</summary>
    Private Sub RaiseDerivedIntValueChanged()
        If (Not (Me.DerivedIntValueChangedEvent) Is Nothing) Then
            RaiseEvent DerivedIntValueChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("DerivedIntValue")
    End Sub
    
    '''<summary>Raises the <see cref='DerivedObjectChanged'/> event.</summary>
    Private Sub RaiseDerivedObjectChanged()
        If (Not (Me.DerivedObjectChangedEvent) Is Nothing) Then
            RaiseEvent DerivedObjectChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("DerivedObject")
    End Sub
    
    '''<summary>Raises the <see cref='MockChanged'/> event.</summary>
    Private Sub RaiseMockChanged()
        If (Not (Me.MockChangedEvent) Is Nothing) Then
            RaiseEvent MockChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("Mock")
    End Sub
End Class
